#include<bits/stdc++.h>
using namespace std;
int n,m,k,cnt,V;
int d[100005],v[100005],a[100005],p[100005];
double f[100005];
bool b;
void solve()
{
    int b=0;
    cnt=0;
    cin>>n>>m>>k>>V;
    for(int i=1;i<=n;i++)
        cin>>d[i]>>v[i]>>a[i];
    for(int i=1;i<=m;i++)
        cin>>p[i];
    sort(p+1,p+m+1);
    for(int i=1;i<=n;i++){
        if(v[i]>V&&d[i]<=p[m]){
            cnt++;
            b=1;
        }
    }
    cout<<cnt<<" "<<m-b<<endl;
}
int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int T;
    cin>>T;
    while (T--)solve();
    return 0;
}
